//-------------------------------------------------------------------------------------------------------
// VST Plug-Ins SDK
// Version 2.4		
//
// Category     : VST 2.x SDK Samples
// Filename     : InverseChannels.cpp
// Created by   : Timothe Faudot
// Description  : Simple  plugin that inverse left and right channels
//
//-------------------------------------------------------------------------------------------------------

#include "InverseChannels.h"

//-------------------------------------------------------------------------------------------------------
AudioEffect* createEffectInstance (audioMasterCallback audioMaster)
{
	return new InverseChannels (audioMaster);
}

//-------------------------------------------------------------------------------------------------------
InverseChannels::InverseChannels (audioMasterCallback audioMaster)
: AudioEffectX (audioMaster, 1, 1)	// 1 program, 1 parameter only
{
	setNumInputs (2);		// stereo in
	setNumOutputs (2);		// stereo out
	setUniqueID ('InverseChannelPlugin');	// identify
	canProcessReplacing ();	// supports replacing output
	canDoubleReplacing ();	// supports double precision processing

	vst_strncpy (programName, "Default", kVstMaxProgNameLen);	// default program name
}

//-------------------------------------------------------------------------------------------------------
InverseChannels::~InverseChannels ()
{
	// nothing to do here
}

//-------------------------------------------------------------------------------------------------------
void InverseChannels::setProgramName (char* name)
{
	vst_strncpy (programName, name, kVstMaxProgNameLen);
}

//-----------------------------------------------------------------------------------------
void InverseChannels::getProgramName (char* name)
{
	vst_strncpy (name, programName, kVstMaxProgNameLen);
}

//------------------------------------------------------------------------
bool InverseChannels::getEffectName (char* name)
{
	vst_strncpy (name, "Channel inverser", kVstMaxEffectNameLen);
	return true;
}

//------------------------------------------------------------------------
bool InverseChannels::getProductString (char* text)
{
	vst_strncpy (text, "Inverse Channels", kVstMaxProductStrLen);
	return true;
}

//------------------------------------------------------------------------
bool InverseChannels::getVendorString (char* text)
{
	vst_strncpy (text, "Faudot Timothe", kVstMaxVendorStrLen);
	return true;
}

//-----------------------------------------------------------------------------------------
VstInt32 InverseChannels::getVendorVersion ()
{ 
	return 1000; 
}

//-----------------------------------------------------------------------------------------
void InverseChannels::processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames)
{
    float* in1  =  inputs[0];
    float* in2  =  inputs[1];
    float* out1 = outputs[0];
    float* out2 = outputs[1];

    while (--sampleFrames >= 0)
    {
        (*out1++) = (*in2++);
        (*out2++) = (*in1++);
    }
}

//-----------------------------------------------------------------------------------------
void InverseChannels::processDoubleReplacing (double** inputs, double** outputs, VstInt32 sampleFrames)
{
    double* in1  =  inputs[0];
    double* in2  =  inputs[1];
    double* out1 = outputs[0];
    double* out2 = outputs[1];

    while (--sampleFrames >= 0)
    {
        (*out1++) = (*in2++);
        (*out2++) = (*in1++);
    }
}
